package com.boot.ys.mybatisplus.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.boot.ys.mybatisplus.entity.Excel;
import com.boot.ys.mybatisplus.mapper.ExcelMapper;
import com.boot.ys.mybatisplus.result.Result;
import com.boot.ys.mybatisplus.service.ExcelService;
import com.boot.ys.mybatisplus.service.impl.ExcelServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.bytebuddy.implementation.bind.annotation.Pipe;
import org.apache.xmlbeans.impl.xb.xsdschema.Public;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping(value = "/excel")
@Api(tags = "导入导出Excel")
public class ExcelController {

    Logger log = LoggerFactory.getLogger(ExcelController.class);


    @Autowired
    private ExcelService excelService;

    @Autowired
    private ExcelMapper excelMapper;

    /**
     * 这里我写整合Apache Poi对Excel的导入导出
     *这里关于读取Excel里面的文件，要自己创建.xlsx 和.xls 不能通过改变文件名后缀的方式来改变要不然会报错
     * .xls是2003的，.xlsx是2007的
     */
    //导入 POI
    @ApiOperation("导入Excel")
    @PostMapping("/readExcelPoi")
    public void readExcelPoi(@RequestParam("filename") MultipartFile file){
        excelService.readExcelPoi(file);
    }

    //导出Excel POI
    @GetMapping("/exportExcel")
    public void exportExcel(HttpServletResponse response){
        excelService.exportExcel(response);
    }




}
